﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QLK.Database;
using QLK.Database.BLLs;

namespace QLK.Web
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        private string _strID;
        private CategoryBLL CateBLL = new CategoryBLL();
        private Category Cates;

        protected void Page_Load(object sender, EventArgs e)
        {
            _strID = Request.QueryString[Columns.CategoryID];
            if (!IsPostBack)
            {                
                if (string.IsNullOrEmpty(_strID))
                    txtCategoryName.Text = null;
                else
                    txtCategoryName.Text = Request.QueryString[Columns.CategoryName];
            }
        }

        protected void btnViewCategory_Click(object sender, EventArgs e)
        {
            //Response.Redirect();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_strID))
            {
                Cates = new Category();
                Cates.CategoryName = txtCategoryName.Text;
                if (CateBLL.Cate_Insert(Cates))
                    lblWarning.Text = "Insert category successfully";
                else
                    lblWarning.Text = "Insert failed";
            }
            else
            {
                Cates = new Category();
                Cates.CategoryID = int.Parse(_strID);
                Cates.CategoryName = txtCategoryName.Text;
                if (CateBLL.Cate_UpdateByID(Cates))
                    lblWarning.Text = "Update category successfully";
                else
                    lblWarning.Text = "Update failed";
            }
        }
    }
}
